/*
 * Rect.cpp
 *
 *  Created on: 2011-03-01
 *      Author: kamil
 */

#include "mgr/util/Rect.h"
#include <stdlib.h>
#include <iostream>

Rect::Rect() : x(0), y(0), w(0), h(0){

}

Rect::Rect(double _x, double _y, double _w, double _h)
: x(_x), y(_y), w(_w), h(_h)
{

}

Rect::~Rect() {

}

Vector2d Rect::randomPoint() const{
	double r1 = rand() / (double) RAND_MAX;
	double r2 = rand() / (double) RAND_MAX;

	return Vector2d(r1 * w + x, r2 * h + y);
}

bool Rect::contains(Vector2d point) const{
	return contains(point.x, point.y);
}
bool Rect::contains(double px, double py) const{
	if (x <= px && px <= x + w && y <= py && py <= y + h) return true;
	return false;
}

std::ostream & operator<<(std::ostream & os, const Rect & r ){
	os<<"r("<<r.x<<","<<r.y<<","<<r.w<<","<<r.h<<")";
	return os;
}
